package com.micangcaihang.common.utils;

import android.app.Activity;
import android.view.Window;

import com.micangcaihang.common.widget.dialog.LoadingDialog;


/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayonggmail@gmail.com
 *     time   : 2017/04/17
 *     desc   : 加载对话框工具类
 *     version: 1.0
 * </pre>
 */

public class LoadDialogUtil {

    static LoadingDialog sLoadingDialog;

    public static LoadingDialog showMaterLoading(Activity context, String text) {
        if (sLoadingDialog != null)
            hideMaterLoading();
        sLoadingDialog = new LoadingDialog(context);
        sLoadingDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        sLoadingDialog.setCanceledOnTouchOutside(false);
        sLoadingDialog.show(text);
        if (!context.isFinishing()) {
            sLoadingDialog.show();
        }
        return sLoadingDialog;
    }

    public static void hideMaterLoading() {
        if ((sLoadingDialog != null) && (sLoadingDialog.isShowing())) {
            sLoadingDialog.dismiss();
            sLoadingDialog = null;
        }
    }
}
